# @Time    :2025/4/12 8:14
# list1 = [1, 3, 56, 6, 7]
# for i in range(len(list1) - 2, 1, -1):  # 倒序，前包后不包#,6,56
#     print(list1[i])
# print("-----------")
# for j in range(1, min(9, len(list1))):
#     print(list1[j])  # 3,56,6,7
#
# print("-----------")


#    """遍历数组中元素"""
# def for_each(self,size, func):
#
#     for i in range(size):
#         func(items[i])
# items = [1, 2, 35, 7, 9]
# size = 3
#
# for_each(items,size,lambda x:print(f"当前元素：{x}"))
#

class Array:
    def __init__(self, size, item):
        self.items = item
        self.size = size

    def for_each(self, func):
        for i in range(self.size):  # 下标从0到 self.size-1
            func(self.items[i])  # self.items[i]是当前遍历到的元素，#本行表示将当前元素作为参数传递给func


#
# items = [1, 2, 35, 7, 9]
# size = 3
#
# a1 = Array(3, items)
# a1.for_each(print)


# aa=[1,23,4]
# size=2
# a2 = Array(2,aa)
# a2.for_each(print)


# class Array:
#     def __init__(self, items, size):
#         self.items = items  # 数组存储空间
#         self.size = size    # 当前有效元素个数
#
#     def for_each(self, func):
#         """遍历数组中元素"""
#         for i in range(self.size):  # 下标从 0 到 self.size - 1
#             func(self.items[i])     # 对每个元素调用 func
#
#
# # 初始化数组
# items = [10, 20, 30, None]
# size = 3
# array = Array(items, size)
#
# # 定义一个简单的函数
# def print_element(element):
#     print(f"当前元素: {element}")
#
# # 调用 for_each 方法
# array.for_each(print_element)

# --------------
# res = "["
# res += 10  # 错 因为这里是int类型不能进行字符串拼接
# print(res)

# ---
# res = "["
# res += str(10 ) # 对
# res+="]"
# print(res)

# list1 = [1, 3, 56, 6, 7]
# for i in list1:
#     print(i)

# list1 = [1, 3, 56, 6, 7]
# for i in range(len(list1) -1, 1, -1):  # 倒序，前包后不包#7,6,56
#     print(list1[i])

list1 = [1, 3, 56, 6, 7]
for i in range(len(list1)-1):#1, 3, 56, 6
    print(list1[i])

list1 = [1, 3, 56, 6, 7]
for i in range(len(list1) - 1,0,-1):  # 7, 6, 56, 3
    print(list1[i])
